package chapter11;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EventQs {
    private Frame frame = new Frame("测试");
    Button ok = new Button("确定");
    TextField tf = new TextField(25);

    public void init() {
        ok.addActionListener(new OkListener());
        frame.add(tf);
        frame.add(ok, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }

    class OkListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("用户点击了ok按钮");
            tf.setText(ok.getLabel());
        }
    }

    public static void main(String[] args) {
        new EventQs().init();
    }
}
